<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <template #operationAfterExtend="{ record }">
        <!-- <a-link @click="handleClick(record)">摄像头特殊事件处理</a-link> -->
      </template>
    </ma-crud>
    <a-drawer
      :width="1200"
      :visible="visible"
      @ok="handleOk"
      @cancel="handleCancel"
      unmountOnClose
    >
      <template #title>特殊事件处理流程</template>
      <dispositionManage :equipment_ids="equipment_ids" v-if="visible">
      </dispositionManage>
    </a-drawer>
  </div>
</template>
<script setup>
import { ref, reactive } from "vue";
import secureEquipmentManage from "@/api/secure/secureEquipmentManage";
import dispositionManage from "@/views/secure/dispositionManage/index.vue";
import { Message } from "@arco-design/web-vue";
import tool from "@/utils/tool";
import * as common from "@/utils/common";

const crudRef = ref();
const equipment_ids = ref();
const visible = ref(false);

const numberOperation = (newValue, id, numberName) => {
  secureEquipmentManage
    .numberOperation({ id, numberName, numberValue: newValue })
    .then((res) => {
      res.success && Message.success(res.message);
    })
    .catch((e) => {
      console.log(e);
    });
};

const handleClick = (row) => {
  equipment_ids.value = row.id;
  visible.value = true;
};
const handleOk = () => {
  visible.value = false;
};
const handleCancel = () => {
  visible.value = false;
};

const switchStatus = (statusValue, id, statusName) => {
  secureEquipmentManage
    .changeStatus({ id, statusName, statusValue })
    .then((res) => {
      res.success && Message.success(res.message);
    })
    .catch((e) => {
      console.log(e);
    });
};

const options = reactive({
  id: "flyos_secure_equipment_manage",
  rowSelection: {
    showCheckedAll: true,
  },
  pk: "id",
  operationColumn: true,
  operationWidth: 160,
  formOption: {
    viewType: "modal",
    width: 600,
  },
  api: secureEquipmentManage.getList,
  recycleApi: secureEquipmentManage.getRecycleList,
  add: {
    show: true,
    api: secureEquipmentManage.save,
    auth: ["secure:equipmentManage:save"],
  },
  edit: {
    show: true,
    api: secureEquipmentManage.update,
    auth: ["secure:equipmentManage:update"],
  },
  delete: {
    show: true,
    api: secureEquipmentManage.deletes,
    auth: ["secure:equipmentManage:delete"],
    realApi: secureEquipmentManage.realDeletes,
    realAuth: ["secure:equipmentManage:realDeletes"],
  },
  recovery: {
    show: true,
    api: secureEquipmentManage.recoverys,
    auth: ["secure:equipmentManage:recovery"],
  },
  import: {
    show: true,
    url: "secure/equipmentManage/import",
    templateUrl: "secure/equipmentManage/downloadTemplate",
    auth: ["secure:equipmentManage:import"],
  },
  export: {
    show: true,
    url: "secure/equipmentManage/export",
    auth: ["secure:equipmentManage:export"],
  },
});

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入ID",
    },
  },
  {
    title: "设备名称",
    dataIndex: "name",
    formType: "input",
    search: true,
  },
  {
    title: "通道名称",
    dataIndex: "jk_name",
    formType: "input",
    search: true,
  },
  {
    title: "纬度",
    dataIndex: "latitude",
    formType: "input",
    search: true,
  },
  {
    title: "经度",
    dataIndex: "longitude",
    formType: "input",
    search: true,
  },
  {
    title: "协议类型",
    dataIndex: "xie_type",
    formType: "input",
    search: true,
  },
  {
    title: "设备类型",
    dataIndex: "supervisory_type",
    align: "center",
    formType: "select",
    search: false,
    dict: {
      // 远程通用接口请求，新版代码生成都有一个 remote 接口
      remote: "secure/equipmentType/remote",
      // 指定组件接收的props
      props: { label: "name", value: "id" },
      // 开启分页
      openPage: true,
      // 远程请求配置项
      remoteOption: {
        // 按用户名排序
        sort: { id: "desc" }, // 如果不指定排序方式，默认为正序排序
        // 设置查询的字段
        select: ["id", "name"],
        // 设置数据过滤
        filter: {},
        // 关联模型
        relations: [],
      },
      translation: true,
    },
  },
  {
    title: "设备状态",
    dataIndex: "equipment_status",
    formType: "select",
    search: true,
    commonRules: {
      required: true,
      message: "请输入设备状态",
    },
    dict: {
      name: "equipment_status",
      props: {
        label: "title",
        value: "key",
      },
      translation: true,
    },
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true,
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true,
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true,
  },
]);
</script>
<script>
export default { name: "secure:equipmentManage" };
</script>
